package g

import (
	//"fmt"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	//_ "github.com/go-sql-driver/mysql"
	_ "github.com/mattn/go-sqlite3"
	log "github.com/ulricqin/goutils/logtool"
)

//设置环境
func InitEnv() {
	Cfg := beego.AppConfig
	// log
	logLevel := Cfg.String("log_level")
	log.SetLevelWithDefault(logLevel, "info")

	// database
	/*
		dbUser := Cfg.String("db_user")
		dbPass := Cfg.String("db_pass")
		dbHost := Cfg.String("db_host")
		dbPort := Cfg.String("db_port")
		dbName := Cfg.String("db_name")
		maxIdleConn, _ := Cfg.Int("db_max_idle_conn")
		maxOpenConn, _ := Cfg.Int("db_max_open_conn")
		dbLink := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbUser, dbPass, dbHost, dbPort, dbName) + "&loc=Asia%2FChongqing"

		orm.RegisterDriver("mysql", orm.DRMySQL)
		orm.RegisterDataBase("default", "mysql", dbLink, maxIdleConn, maxOpenConn)
	*/

	orm.RegisterDriver("sqlite", orm.DRSqlite)
	orm.RegisterDataBase("default", "sqlite3", "./sql/sqlite/goetl.db")

	RunMode := Cfg.String("runmode")
	if RunMode == "dev" {
		orm.Debug = true
	}
	MyAgentManager.Start()
}
